namespace Todo;

public class UserServiceImpl : IUser
{
    private readonly ApplicationDBContext _applicationDbContext;
    
    public UserServiceImpl(ApplicationDBContext applicationDbContext)
    {
        _applicationDbContext = applicationDbContext;
    }
    public User Login(string username, string password)
    {
        var login = _applicationDbContext.Users.Where( u => u.Username == username && u.Password == password);
        return login.FirstOrDefault();
    }

    public bool Register(string username, string password)
    {
        _applicationDbContext.Users.Add(new User() { Id = Guid.NewGuid(),Username = username, Password = password });
        var saveChanges = _applicationDbContext.SaveChanges();
        return saveChanges > 0;
    }
}